@echo off
title Ruoyi-ai Application Stop Script

set APP_NAME=ruoyi-admin
set APP_HOME=%~dp0
set PID_FILE=%APP_HOME%app.pid

REM 检查PID文件是否存在
if not exist "%PID_FILE%" (
    echo PID file not found: %PID_FILE%
    echo Application may not be running or was started without writing PID file.
    pause
    exit /b 1
)

REM 读取PID
set /p PID=<"%PID_FILE%"

REM 检查进程是否存在并终止
taskkill /PID %PID% /T /F >nul 2>&1

if %errorlevel% equ 0 (
    echo Stopping %APP_NAME% ^(PID: %PID%^)...
    echo %APP_NAME% stopped successfully.
) else (
    echo Failed to stop %APP_NAME%. Process may not be running.
)

REM 删除PID文件
del /f /q "%PID_FILE%" >nul 2>&1

pause